<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>JavaScript知识点总结(八.JavaScript内置对象) | 小何blog (记录美好)</title><meta name="keywords" content="系列🏬,JavaScript,ECMAScript"><meta name="author" content="六根清静"><meta name="copyright" content="六根清静"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta http-equiv="Cache-Control" content="no-transform"><meta http-equiv="Cache-Control" content="no-siteapp"><meta name="description" content="JavaScript内置对象与宿主无关，独立于宿主环境的ECMAScript实现提供的对象，在ECMAScript 程序开始执行时出现。在 ECMAScript 程序开始执行前就存在，本身就是实例化内置对象，开发者无需再去实例化。">
<meta property="og:type" content="article">
<meta property="og:title" content="JavaScript知识点总结(八.JavaScript内置对象)">
<meta property="og:url" content="https://liugenqingjing2.coding.me/2020/09/14/JavaScript%E7%9F%A5%E8%AF%86%E7%82%B9%E6%80%BB%E7%BB%93-%E5%85%AB-JavaScript-%E5%86%85%E7%BD%AE%E5%AF%B9%E8%B1%A1/index.html">
<meta property="og:site_name" content="小何blog (记录美好)">
<meta property="og:description" content="JavaScript内置对象与宿主无关，独立于宿主环境的ECMAScript实现提供的对象，在ECMAScript 程序开始执行时出现。在 ECMAScript 程序开始执行前就存在，本身就是实例化内置对象，开发者无需再去实例化。">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20200914/it!NQ33FHCp7.jpg">
<meta property="article:published_time" content="2020-09-14T14:07:15.000Z">
<meta property="article:modified_time" content="2021-01-10T12:10:38.536Z">
<meta property="article:author" content="六根清静">
<meta property="article:tag" content="系列🏬">
<meta property="article:tag" content="JavaScript">
<meta property="article:tag" content="ECMAScript">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20200914/it!NQ33FHCp7.jpg"><link rel="shortcut icon" href="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20200907/wOu*ZmuVb5A4.png"><link rel="canonical" href="https://liugenqingjing2.coding.me/2020/09/14/JavaScript%E7%9F%A5%E8%AF%86%E7%82%B9%E6%80%BB%E7%BB%93-%E5%85%AB-JavaScript-%E5%86%85%E7%BD%AE%E5%AF%B9%E8%B1%A1/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//hm.baidu.com"/><link rel="preconnect" href="//fonts.googleapis.com" crossorigin="crossorigin"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.css"><script>var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?e829919a4d931d733ee74d5d97a51582";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script><link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Titillium+Web&amp;display=swap"><script>var GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: {"path":"search.xml","languages":{"hits_empty":"找不到您查询的内容：${query}"}},
  translate: {"defaultEncoding":2,"translateDelay":0,"msgToTraditionalChinese":"繁","msgToSimplifiedChinese":"簡"},
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '天',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: {"limitCount":20,"languages":{"author":"作者: 六根清静","link":"链接: ","source":"来源: 小何blog (记录美好)","info":"著作权归作者所有。商业转载请联系作者获得授权，非商业转载请注明出处。"}},
  ClickShowText: undefined,
  lightbox: 'fancybox',
  Snackbar: {"chs_to_cht":"你已切换为繁体","cht_to_chs":"你已切换为简体","day_to_night":"你已切换为深色模式","night_to_day":"你已切换为浅色模式","bgLight":"#49b1f5","bgDark":"#121212","position":"bottom-left"},
  justifiedGallery: {
    js: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/js/jquery.justifiedGallery.min.js',
    css: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/css/justifiedGallery.min.css'
  },
  isPhotoFigcaption: true,
  islazyload: true,
  isanchor: true
};

var saveToLocal = {
  set: function setWithExpiry(key, value, ttl) {
    const now = new Date()
    const expiryDay = ttl * 86400000
    const item = {
      value: value,
      expiry: now.getTime() + expiryDay,
    }
    localStorage.setItem(key, JSON.stringify(item))
  },

  get: function getWithExpiry(key) {
    const itemStr = localStorage.getItem(key)

    if (!itemStr) {
      return undefined
    }
    const item = JSON.parse(itemStr)
    const now = new Date()

    if (now.getTime() > item.expiry) {
      localStorage.removeItem(key)
      return undefined
    }
    return item.value
  }
}</script><script id="config_change">var GLOBAL_CONFIG_SITE = { 
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2021-01-10 20:10:38'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(function () {  window.activateDarkMode = function () {
    document.documentElement.setAttribute('data-theme', 'dark')
    if (document.querySelector('meta[name="theme-color"]') !== null) {
      document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
    }
  }
  window.activateLightMode = function () {
    document.documentElement.setAttribute('data-theme', 'light')
   if (document.querySelector('meta[name="theme-color"]') !== null) {
      document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
    }
  }
  const autoChangeMode = '2'
  const t = saveToLocal.get('theme')
  if (autoChangeMode === '1') {
    const isDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches
    const isLightMode = window.matchMedia('(prefers-color-scheme: light)').matches
    const isNotSpecified = window.matchMedia('(prefers-color-scheme: no-preference)').matches
    const hasNoSupport = !isDarkMode && !isLightMode && !isNotSpecified
    if (t === undefined) {
      if (isLightMode) activateLightMode()
      else if (isDarkMode) activateDarkMode()
      else if (isNotSpecified || hasNoSupport) {
        const now = new Date()
        const hour = now.getHours()
        const isNight = hour <= 6 || hour >= 18
        isNight ? activateDarkMode() : activateLightMode()
      }
      window.matchMedia('(prefers-color-scheme: dark)').addListener(function (e) {
        if (saveToLocal.get('theme') === undefined) {
          e.matches ? activateDarkMode() : activateLightMode()
        }
      })
    } else if (t === 'light') activateLightMode()
    else activateDarkMode()
  } else if (autoChangeMode === '2') {
    const now = new Date()
    const hour = now.getHours()
    const isNight = hour <= 6 || hour >= 18
    if (t === undefined) isNight ? activateDarkMode() : activateLightMode()
    else if (t === 'light') activateLightMode()
    else activateDarkMode()
  } else {
    if (t === 'dark') activateDarkMode()
    else if (t === 'light') activateLightMode()
  }const asideStatus = saveToLocal.get('aside-status')
if (asideStatus !== undefined) {
   if (asideStatus === 'hide') {
     document.documentElement.classList.add('hide-aside')
   } else {
     document.documentElement.classList.remove('hide-aside')
   }
}})()</script><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/HCLonely/images@master/others/heartbeat.min.css"><link rel="stylesheet" href="/css/shuo.css"/><link rel="stylesheet" href="/magnetcss/magnet.css"/><link rel="stylesheet" href="/css/calendar.css"/><link rel="stylesheet" href="//at.alicdn.com/t/font_2060620_l0j6b710zk.css"/><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/sviptzk/StaticFile_HEXO@latest/butterfly/css/font-awesome-animation.min.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/sviptzk/StaticFile_HEXO@latest/butterfly/css/macblack.css"><link rel="stylesheet" href="/css/change.css"><link rel="stylesheet" href="/news/css/news.css"/><style type="text/css">#toggle-sidebar {bottom: 80px}</style><link rel="stylesheet" href="/magnet/css/catalogMagnet.css"/><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Zfour/Butterfly-double-row-display@1.00/cardlistpost.css"/><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/sviptzk/StaticFile_HEXO@latest/butterfly/css/iconfont.min.css"><link rel="stykesheet" href="https://cdn.jsdelivr.net/gh/sviptzk/StaticFile_HEXO@latest/butterfly/css/pool.min.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/font-awesome/css/font-awesome.min.css"/><link rel="stylesheet" href="/zan/zan.css"><link rel="stylesheet" href="/swiper/swiper.min.css"><link rel="stylesheet" href="/swiper/swiperstyle.css"><style>#article-container.post-content h1:before, h2:before, h3:before, h4:before, h5:before, h6:before { -webkit-animation: avatar_turn_around 1s linear infinite; -moz-animation: avatar_turn_around 1s linear infinite; -o-animation: avatar_turn_around 1s linear infinite; -ms-animation: avatar_turn_around 1s linear infinite; animation: avatar_turn_around 1s linear infinite; }</style><meta name="generator" content="Hexo 5.0.0"></head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><div class="wizard-scene"><div class="wizard-objects"><div class="wizard-square"></div><div class="wizard-circle"></div><div class="wizard-triangle"></div></div><div class="wizard"><div class="wizard-body"></div><div class="wizard-right-arm"><div class="wizard-right-hand"></div></div><div class="wizard-left-arm"><div class="wizard-left-hand"></div></div><div class="wizard-head"><div class="wizard-beard"></div><div class="wizard-face"><div class="wizard-adds"></div></div><div class="wizard-hat"><div class="wizard-hat-of-the-hat"></div><div class="wizard-four-point-star --first"></div><div class="wizard-four-point-star --second"></div><div class="wizard-four-point-star --third"></div></div></div></div></div></div><div id="web_bg"></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="author-avatar"><img class="avatar-img" data-lazy-src="http://01.027cgb.com/632500/1576904533264.jpg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data"><div class="data-item is-center"><div class="data-item-link"><a href="/archives/"><div class="headline">文章</div><div class="length-num">138</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/tags/"><div class="headline">标签</div><div class="length-num">63</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/categories/"><div class="headline">分类</div><div class="length-num">8</div></a></div></div></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/stars/"><i class="fa-fw fas fa-star faa-shake animated-hover"></i><span> 收藏网址</span></a></div><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw iconfont icon-zhuye faa-shake animated-hover"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="/blog.html"><i class="fa-fw iconfont icon-Artboard faa-shake animated-hover"></i><span> 博客</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw iconfont icon-guidang faa-shake animated-hover"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw iconfont icon-biaoqian faa-shake animated-hover"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw iconfont icon-yule1"></i><span> 娱乐</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page" href="/movies/"><i class="fa-fw iconfont icon-yingshi faa-shake animated-hover"></i><span> 影视</span></a></li><li><a class="site-page" href="/games/"><i class="fa-fw iconfont icon-youxi1 faa-shake animated-hover"></i><span> 游戏</span></a></li><li><a class="site-page" href="/galleryGroup"><i class="fa-fw iconfont icon-tuku faa-shake animated-hover"></i><span> 图库</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/messagepad/"><i class="fa-fw iconfont icon-ziyuan6 faa-shake animated-hover"></i><span> 留言板</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw iconfont icon-icon_xinyong_xianxing_jijin- faa-shake animated-hover"></i><span> 友情链接</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw iconfont icon-guanyuwomen faa-shake animated-hover"></i><span> 关于我</span></a></div></div></div></div><div id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url(https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20200914/it!NQ33FHCp7.jpg)"><nav id="nav"><span id="blog_name"><a id="site-name" href="/">小何blog (记录美好)</a></span><span id="menus"><div id="search_button"><a class="site-page social-icon search"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/stars/"><i class="fa-fw fas fa-star faa-shake animated-hover"></i><span> 收藏网址</span></a></div><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw iconfont icon-zhuye faa-shake animated-hover"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="/blog.html"><i class="fa-fw iconfont icon-Artboard faa-shake animated-hover"></i><span> 博客</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw iconfont icon-guidang faa-shake animated-hover"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw iconfont icon-biaoqian faa-shake animated-hover"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw iconfont icon-yule1"></i><span> 娱乐</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page" href="/movies/"><i class="fa-fw iconfont icon-yingshi faa-shake animated-hover"></i><span> 影视</span></a></li><li><a class="site-page" href="/games/"><i class="fa-fw iconfont icon-youxi1 faa-shake animated-hover"></i><span> 游戏</span></a></li><li><a class="site-page" href="/galleryGroup"><i class="fa-fw iconfont icon-tuku faa-shake animated-hover"></i><span> 图库</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/messagepad/"><i class="fa-fw iconfont icon-ziyuan6 faa-shake animated-hover"></i><span> 留言板</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw iconfont icon-icon_xinyong_xianxing_jijin- faa-shake animated-hover"></i><span> 友情链接</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw iconfont icon-guanyuwomen faa-shake animated-hover"></i><span> 关于我</span></a></div></div><span class="close" id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></span></span></nav><div id="post-info"><h1 class="post-title">JavaScript知识点总结(八.JavaScript内置对象)</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2020-09-14T14:07:15.000Z" title="发表于 2020-09-14 22:07:15">2020-09-14</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2021-01-10T12:10:38.536Z" title="更新于 2021-01-10 20:10:38">2021-01-10</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E5%89%8D%E7%AB%AF%E5%AD%A6%E4%B9%A0/">前端学习</a></span></div><div class="meta-secondline"> <span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">2.9k</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>10分钟</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h1 id="JavaScript-内置对象："><a href="#JavaScript-内置对象：" class="headerlink" title="JavaScript 内置对象："></a>JavaScript 内置对象：</h1><blockquote>
<p>纯属随笔记录，具体详细教程，请查阅<a target="_blank" rel="noopener" href="https://developer.mozilla.org/zh-CN/">MDN Web 文档</a></p>
</blockquote>
<ul>
<li><h2 id="内置对象："><a href="#内置对象：" class="headerlink" title="内置对象："></a>内置对象：</h2><blockquote>
<ol>
<li>JavaScript 中的对象分为3种：<strong>自定义对象 、内置对象、 浏览器对象</strong></li>
<li><strong>前面两种对象是JS 基础</strong> 内容，属于 <strong>ECMAScript</strong>；  <strong>第三个浏览器对象</strong>属于我们<strong>JS 独有的</strong>， 我们JS API 讲解</li>
<li><strong>内置对象</strong>就是指 JS 语言自带的一些对象，这些对象供开发者使用，并提供了一些常用的或是最基本而必要的功能（属性和方法）</li>
<li><strong>内置对象最大的优点就是帮助我们快速开发</strong></li>
<li><code>JavaScript</code> 提供了多个内置对象：**<code>Math、 Date 、Array、String</code>**等</li>
</ol>
</blockquote>
<hr>
</li>
<li><h2 id="Math-对象"><a href="#Math-对象" class="headerlink" title="Math 对象:"></a>Math 对象:</h2><ul>
<li><h3 id="Math-概述"><a href="#Math-概述" class="headerlink" title="Math 概述:"></a>Math 概述:</h3><ul>
<li><code>Math</code> 对象<strong>不是构造函数</strong>，它具有<strong>数学常数和函数的属性和方法</strong>。<strong>跟数学相关的运算</strong>（求绝对值，取整、最大值等）可以使用 <code>Math</code> 中的成员。</li>
</ul>
<h4 id="常用的如下"><a href="#常用的如下" class="headerlink" title="常用的如下:"></a>常用的如下:</h4><figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="built_in">Math</span>.PI         <span class="comment">// 圆周率</span></span><br><span class="line"><span class="built_in">Math</span>.floor()      <span class="comment">// 向下取整</span></span><br><span class="line"><span class="built_in">Math</span>.ceil()            <span class="comment">// 向上取整</span></span><br><span class="line"><span class="built_in">Math</span>.round()           <span class="comment">// 四舍五入版 就近取整   注意 -3.5   结果是  -3 </span></span><br><span class="line"><span class="built_in">Math</span>.abs()         <span class="comment">// 绝对值</span></span><br><span class="line"><span class="built_in">Math</span>.max()/<span class="built_in">Math</span>.min()     <span class="comment">// 求最大和最小值 </span></span><br></pre></td></tr></table></figure>

<ul>
<li><strong>注意：</strong>上面的方法<strong>必须带括号</strong></li>
</ul>
<hr>
</li>
<li><h3 id="随机数方法-random-："><a href="#随机数方法-random-：" class="headerlink" title="随机数方法 random()："></a>随机数方法 random()：</h3><ul>
<li><code>random()</code> 方法可以<strong>随机返回一个小数</strong>，其取值范围是 <strong>[0，1)，左闭右开 0 &lt;= x &lt; 1</strong> </li>
<li>下面我们利用<code>random()</code>方法封装一个函数:</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">getRandom</span>(<span class="params">min, max</span>) </span>&#123;</span><br><span class="line">  <span class="keyword">return</span> <span class="built_in">Math</span>.floor(<span class="built_in">Math</span>.random() * (max - min + <span class="number">1</span>)) + min; </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ul>
<li>得到一个两数之间的<strong>随机整数</strong>，包括两个数在内</li>
<li>更多请查阅<a target="_blank" rel="noopener" href="https://developer.mozilla.org/zh-CN/">MDN Web 文档</a></li>
</ul>
</li>
</ul>
<hr>
</li>
<li><h2 id="日期对象"><a href="#日期对象" class="headerlink" title="日期对象:"></a>日期对象:</h2><ul>
<li><h3 id="Date-概述"><a href="#Date-概述" class="headerlink" title="Date 概述:"></a>Date 概述:</h3><ul>
<li><strong>Date 对象和 Math 对象</strong>不一样，他是<strong>一个构造函数</strong>，所以我们需要<strong>实例化</strong>后才能使用</li>
<li><strong>Date 实例用来处理日期和时间</strong></li>
</ul>
<hr>
</li>
<li><h3 id="Date-方法的使用"><a href="#Date-方法的使用" class="headerlink" title="Date()方法的使用:"></a>Date()方法的使用:</h3><ul>
<li><strong>获取当前时间必须实例化</strong></li>
</ul>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">var</span> now = <span class="keyword">new</span> <span class="built_in">Date</span>();</span><br><span class="line"><span class="built_in">console</span>.log(now);</span><br></pre></td></tr></table></figure>

<ul>
<li><code>Date()</code> 构造函数的参数</li>
</ul>
<blockquote>
<p>如果括号里面有时间，就返回参数里面的时间。例如日期格式字符串为<strong>‘2019-5-1’</strong>，可以写成<code>new Date(&#39;2019-5-1&#39;) </code> 或者 <code>new Date(&#39;2019/5/1&#39;)</code></p>
</blockquote>
<ul>
<li>如果<code>Date()</code>不写参数，就返回当前时间</li>
<li>如果<code>Date()</code>里面写参数，就返回括号里面输入的时间 </li>
</ul>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">var</span> now = <span class="keyword">new</span> <span class="built_in">Date</span>();</span><br><span class="line"><span class="built_in">console</span>.log(now);</span><br><span class="line"><span class="keyword">var</span> now = <span class="keyword">new</span> <span class="built_in">Date</span>(<span class="string">&#x27;2021-9-15&#x27;</span>);</span><br><span class="line"><span class="built_in">console</span>.log(now);</span><br></pre></td></tr></table></figure>

<h4 id="效果"><a href="#效果" class="headerlink" title="效果:"></a>效果:</h4><h2 id=""><a href="#" class="headerlink" title=""></a><img src= "/img/loading.gif" data-lazy-src="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20200915/YHe5YB^t@6TC.png" alt="效果图"></h2></li>
<li><h3 id="日期格式化："><a href="#日期格式化：" class="headerlink" title="日期格式化："></a>日期格式化：</h3><ul>
<li>我们想要 <code>2019-8-8  8:8:8</code> 格式的日期，要怎么办？ </li>
<li>需要<strong>获取日期指定的部分</strong>，所以我们要手动的得到这种格式。</li>
</ul>
<table>
<thead>
<tr>
<th align="center">方法名</th>
<th align="center">说明</th>
<th align="center">代码</th>
</tr>
</thead>
<tbody><tr>
<td align="center">getFullYear()</td>
<td align="center">获取当年</td>
<td align="center">Obj.getFullYear()</td>
</tr>
<tr>
<td align="center">getMonth()</td>
<td align="center">获取当月(O-11)</td>
<td align="center">Obj.getMonth0</td>
</tr>
<tr>
<td align="center">getDate()</td>
<td align="center">获取当天日期</td>
<td align="center">Obj.getDate()</td>
</tr>
<tr>
<td align="center">getDay()</td>
<td align="center">获取星期几(周日0到周六6)</td>
<td align="center">Obj.getDay()</td>
</tr>
<tr>
<td align="center">getHours()</td>
<td align="center">获取当前小时</td>
<td align="center">Obj.getHours()</td>
</tr>
<tr>
<td align="center">getMinutes()</td>
<td align="center">获取当前分钟</td>
<td align="center">Obj.getMinutes()</td>
</tr>
<tr>
<td align="center">getSeconds()</td>
<td align="center">获取当前秒钟</td>
<td align="center">Obj.getSeconds()</td>
</tr>
</tbody></table>
<hr>
</li>
<li><h3 id="案例"><a href="#案例" class="headerlink" title="案例:"></a>案例:</h3><ul>
<li><strong>获取当前日期</strong></li>
</ul>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">var</span> date = <span class="keyword">new</span> <span class="built_in">Date</span>()</span><br><span class="line"><span class="keyword">var</span> year = date.getFullYear()</span><br><span class="line"><span class="keyword">var</span> month = date.getMonth() + <span class="number">1</span></span><br><span class="line"><span class="keyword">var</span> day = date.getDate()</span><br><span class="line"><span class="keyword">var</span> xingqi = date.getDay()</span><br><span class="line"><span class="keyword">var</span> arr = [<span class="string">&quot;星期日&quot;</span>,<span class="string">&quot;星期一&quot;</span>,<span class="string">&quot;星期二&quot;</span>,<span class="string">&quot;星期三&quot;</span>,<span class="string">&quot;星期四&quot;</span>,<span class="string">&quot;星期五&quot;</span>,<span class="string">&quot;星期六&quot;</span>]</span><br><span class="line"><span class="built_in">console</span>.log(year + <span class="string">&quot;年&quot;</span> + month + <span class="string">&quot;月&quot;</span> + day + <span class="string">&quot;日&quot;</span> + arr[xingqi]);</span><br></pre></td></tr></table></figure>

<h4 id="效果-1"><a href="#效果-1" class="headerlink" title="效果:"></a>效果:</h4><p><img src= "/img/loading.gif" data-lazy-src="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20200915/e6Rt1IXI71JE.png" alt="当前日期"></p>
<ul>
<li><strong>封装当前时间</strong></li>
</ul>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">getTime</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">    <span class="keyword">var</span> date = <span class="keyword">new</span> <span class="built_in">Date</span>()</span><br><span class="line">    <span class="keyword">var</span> hours = date.getHours()</span><br><span class="line">    hours = hours&lt;<span class="number">10</span> ? <span class="string">&#x27;0&#x27;</span>+ hours : hours</span><br><span class="line">    <span class="keyword">var</span> minutes = date.getMinutes()</span><br><span class="line">    minutes = minutes&lt;<span class="number">10</span> ? <span class="string">&#x27;0&#x27;</span>+ minutes : minutes</span><br><span class="line">    <span class="keyword">var</span> seconds = date.getSeconds()</span><br><span class="line">    seconds = seconds&lt;<span class="number">10</span> ? <span class="string">&#x27;0&#x27;</span>+ seconds : seconds</span><br><span class="line">    <span class="keyword">return</span> hours + <span class="string">&quot;:&quot;</span> + minutes + <span class="string">&quot;:&quot;</span> + seconds</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="built_in">console</span>.log(getTime());</span><br></pre></td></tr></table></figure>

<h4 id="效果-2"><a href="#效果-2" class="headerlink" title="效果:"></a>效果:</h4><p><img src= "/img/loading.gif" data-lazy-src="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20200915/WxTnnU^I2eXD.png" alt="当前日期"></p>
<hr>
</li>
<li><h3 id="获取日期的总的毫秒形式-时间戳-："><a href="#获取日期的总的毫秒形式-时间戳-：" class="headerlink" title="获取日期的总的毫秒形式(时间戳)："></a>获取日期的总的毫秒形式(时间戳)：</h3><ul>
<li><code>Date</code> 对象是基于<strong>1970年1月1日（世界标准时间）起的毫秒数</strong></li>
<li><a target="_blank" rel="noopener" href="https://blog.csdn.net/csdn_kou/article/details/81535452">为什么计算机起始时间从1970年开始?</a></li>
<li>我们经常利用总的<strong>毫秒数来计算时间，因为它更精确</strong></li>
</ul>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="comment">// 实例化Date对象</span></span><br><span class="line"><span class="keyword">var</span> now = <span class="keyword">new</span> <span class="built_in">Date</span>();</span><br><span class="line"><span class="comment">// 1. 用于获取对象的原始值</span></span><br><span class="line"><span class="built_in">console</span>.log(date.valueOf())    </span><br><span class="line"><span class="built_in">console</span>.log(date.getTime())    </span><br><span class="line"><span class="comment">// 2. 简单写可以这么做</span></span><br><span class="line"><span class="keyword">var</span> now = + <span class="keyword">new</span> <span class="built_in">Date</span>();            </span><br><span class="line"><span class="comment">// 3. HTML5中提供的方法，有兼容性问题</span></span><br><span class="line"><span class="keyword">var</span> now = <span class="built_in">Date</span>.now();</span><br></pre></td></tr></table></figure>

<h4 id="效果-3"><a href="#效果-3" class="headerlink" title="效果:"></a>效果:</h4><p><img src= "/img/loading.gif" data-lazy-src="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20200915/z99qCZMAPaLd.png" alt="现在时间戳"></p>
</li>
</ul>
<hr>
</li>
<li><h2 id="数组对象："><a href="#数组对象：" class="headerlink" title="数组对象："></a>数组对象：</h2><ul>
<li><h3 id="数组对象的创建："><a href="#数组对象的创建：" class="headerlink" title="数组对象的创建："></a>数组对象的创建：</h3><blockquote>
<p><strong>创建数组对象的两种方式</strong>：</p>
</blockquote>
<ul>
<li><code>new Array()</code></li>
<li><strong>字面量方式</strong></li>
</ul>
<hr>
</li>
<li><h3 id="检测是否为数组"><a href="#检测是否为数组" class="headerlink" title="检测是否为数组:"></a>检测是否为数组:</h3><ul>
<li><code>instanceof</code> 运算符，可以判断一个对象是否<strong>属于某种类型</strong></li>
<li><code>Array.isArray()</code>用于判断<strong>一个对象是否为数组</strong>，<code>isArray()</code>是 <strong>HTML5 中提供的方法</strong>    </li>
</ul>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">var</span> arr = [<span class="number">1</span>, <span class="number">23</span>];</span><br><span class="line"><span class="keyword">var</span> obj = &#123;&#125;;</span><br><span class="line"><span class="built_in">console</span>.log(arr <span class="keyword">instanceof</span> <span class="built_in">Array</span>); <span class="comment">// true</span></span><br><span class="line"><span class="built_in">console</span>.log(obj <span class="keyword">instanceof</span> <span class="built_in">Array</span>); <span class="comment">// false</span></span><br><span class="line"><span class="built_in">console</span>.log(<span class="built_in">Array</span>.isArray(arr));   <span class="comment">// true</span></span><br><span class="line"><span class="built_in">console</span>.log(<span class="built_in">Array</span>.isArray(obj));   <span class="comment">// false</span></span><br></pre></td></tr></table></figure>

<hr>
</li>
<li><h3 id="添加删除数组元素的方法"><a href="#添加删除数组元素的方法" class="headerlink" title="添加删除数组元素的方法:"></a>添加删除数组元素的方法:</h3><table>
<thead>
<tr>
<th align="center">方法名</th>
<th align="center">说明</th>
<th align="center">返回值</th>
</tr>
</thead>
<tbody><tr>
<td align="center">push(参数1….)</td>
<td align="center">末尾添加一个或多个元素，注意会修改原数组</td>
<td align="center">并返回新的长度</td>
</tr>
<tr>
<td align="center">pop()</td>
<td align="center">删除数组最后—个元素，把数组长度减1，无参数，修改原数组</td>
<td align="center">返回它删除的元素的值</td>
</tr>
<tr>
<td align="center">unshift(参数1…)</td>
<td align="center">向数组的开头添加一个或更多元素，注意修改原数组</td>
<td align="center">并返回新的长度</td>
</tr>
<tr>
<td align="center">shift()</td>
<td align="center">册除数组的第一个元素，数组长度减1无参数、修改原数组</td>
<td align="center">并返回第一个元素的值</td>
</tr>
</tbody></table>
<hr>
</li>
<li><h3 id="数组排序："><a href="#数组排序：" class="headerlink" title="数组排序："></a>数组排序：</h3><table>
<thead>
<tr>
<th align="center">方法名</th>
<th align="center">说明</th>
<th align="center">是否修改原数组</th>
</tr>
</thead>
<tbody><tr>
<td align="center">reverse()</td>
<td align="center">颠倒数组中元素的顺序，无参数</td>
<td align="center">该方法会改变原来的数组返回新数组</td>
</tr>
<tr>
<td align="center">sort()</td>
<td align="center">对数组的元索进行排序</td>
<td align="center">该访法会改变原来的数组返回新数组</td>
</tr>
</tbody></table>
<blockquote>
<h4 id="注"><a href="#注" class="headerlink" title="注:"></a>注:</h4><h4 id="sort-缺陷-js数组的sort方法总会以第一个字符的ASCII值来进行比较排序"><a href="#sort-缺陷-js数组的sort方法总会以第一个字符的ASCII值来进行比较排序" class="headerlink" title="sort()缺陷:  js数组的sort方法总会以第一个字符的ASCII值来进行比较排序"></a><code>sort()</code>缺陷:  js数组的sort方法总会以第一个字符的ASCII值来进行比较排序</h4></blockquote>
<ul>
<li><strong>修改排序完整版:</strong></li>
</ul>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">var</span> arr = [<span class="number">1</span>, <span class="number">64</span>, <span class="number">9</span>, <span class="number">6</span>];</span><br><span class="line">arr.sort(<span class="function"><span class="keyword">function</span>(<span class="params">a, b</span>) </span>&#123;</span><br><span class="line">    <span class="keyword">return</span> b - a;      <span class="comment">// 降a序</span></span><br><span class="line">    <span class="comment">// return a - b;   // 升序</span></span><br><span class="line">&#125;);</span><br><span class="line"><span class="built_in">console</span>.log(arr);</span><br></pre></td></tr></table></figure>

<hr>
</li>
<li><h3 id="数组索引方法"><a href="#数组索引方法" class="headerlink" title="数组索引方法:"></a>数组索引方法:</h3><table>
<thead>
<tr>
<th align="center">方法名</th>
<th align="center">说明</th>
<th align="center">返回值</th>
</tr>
</thead>
<tbody><tr>
<td align="center">indexOf()</td>
<td align="center">数组中查找给定元素的第一个索引</td>
<td align="center">如果存在返回索引号如果不存在，则返回-1。</td>
</tr>
<tr>
<td align="center">lastIndexOf()</td>
<td align="center">在数组中的最后一个的索引，</td>
<td align="center">如果存在返回索引号如果不存在，则返回-1。</td>
</tr>
</tbody></table>
<h4 id="案例数组去重"><a href="#案例数组去重" class="headerlink" title="案例数组去重:"></a>案例数组去重:</h4><figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">unique</span>(<span class="params">arr</span>)</span>&#123;</span><br><span class="line">    <span class="keyword">var</span> newArr = []</span><br><span class="line">    <span class="keyword">for</span>(<span class="keyword">var</span> i = <span class="number">0</span> ; i &lt; arr.length ; i++)&#123;</span><br><span class="line">      <span class="keyword">if</span>(newArr.indexOf(arr[i]) === <span class="number">-1</span>)&#123;</span><br><span class="line">        newArr.push(arr[i])</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> newArr</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="keyword">var</span> arr = [<span class="string">&#x27;小红&#x27;</span>,<span class="string">&#x27;小兰&#x27;</span>,<span class="string">&#x27;小铭&#x27;</span>,<span class="string">&#x27;小朱&#x27;</span>,<span class="string">&#x27;小铭&#x27;</span>]</span><br><span class="line">  <span class="built_in">console</span>.log(unique(arr));</span><br></pre></td></tr></table></figure>

<h4 id="效果-4"><a href="#效果-4" class="headerlink" title="效果:"></a>效果:</h4><p><img src= "/img/loading.gif" data-lazy-src="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20200916/SS*vOzyCzkzA.png" alt="数组去重效果图"></p>
<hr>
</li>
<li><h3 id="数组转换为字符串"><a href="#数组转换为字符串" class="headerlink" title="数组转换为字符串:"></a>数组转换为字符串:</h3><table>
<thead>
<tr>
<th align="center">方法名</th>
<th align="center">说明</th>
<th align="center">返回值</th>
</tr>
</thead>
<tbody><tr>
<td align="center">toString()</td>
<td align="center">把数组转换成字符串，逗号分隔每一项</td>
<td align="center">返回一个字符串</td>
</tr>
<tr>
<td align="center">join(‘分隔符’)</td>
<td align="center">方法用于把数组中的所有元素转换为一个字符串.</td>
<td align="center">返回一个字符串</td>
</tr>
</tbody></table>
<hr>
</li>
<li><h3 id="其他方法"><a href="#其他方法" class="headerlink" title="其他方法:"></a>其他方法:</h3><table>
<thead>
<tr>
<th align="center">方法名</th>
<th align="center">说明</th>
<th align="center">返回值</th>
</tr>
</thead>
<tbody><tr>
<td align="center">concat()</td>
<td align="center">连接两个或多个数组不影响原数组</td>
<td align="center">返回一个新的数组</td>
</tr>
<tr>
<td align="center">slice()</td>
<td align="center">数组截取slice(begin, end)</td>
<td align="center">返回被截取项目的新数组</td>
</tr>
<tr>
<td align="center">splice()</td>
<td align="center">数组删除splice(第几个开始,要删除个数)</td>
<td align="center">返回被删除项目的新数组,注意: 这个会影响原数组</td>
</tr>
</tbody></table>
<h4 id="解释"><a href="#解释" class="headerlink" title="解释:"></a>解释:</h4><ul>
<li><p><strong><code>slice(start,end)：</code>**方法可从已有数组中返回选定的元素，返回一个新数组，包含从</strong>start到end（不包含该元素）的数组元素**。</p>
<p><strong>注意：</strong></p>
<ol>
<li>​    该方法<strong>不会改变原数组</strong>，而是返回一个子数组，如果想<strong>删除数组中的一段元素</strong>，应该使用    <code>Array.splice()</code>方法。</li>
<li>同时**<code>slice(start,end)</code><strong>可以作用于</strong>字符串的切割**</li>
</ol>
<p><strong>参数</strong>:</p>
<ol>
<li><strong>start参数：</strong> <strong>必须</strong>，规定从何处开始选取，如果为负数，规定从数组尾部算起的位置，-1是指最后一个元素。</li>
<li><strong>end参数： ** **可选</strong>（如果该参数没有指定，那么切分的数组包含从start倒数组结束的所有元素，如果这个参数为负数，那么规定是从数组尾部开始算起的元素）。</li>
</ol>
</li>
<li><p><strong>`splice()：·</strong>该方法向或者从数组中添加或者删除项目，返回被删除的项目。<strong>（该方法会改变原数组）</strong></p>
<p><strong>参数:</strong></p>
<p><strong><code>splice（index,howmany,item1,...itemX）</code></strong></p>
<ol>
<li><code>index</code>参数：<strong>必须，整数</strong>，规定添加或者删除的位置，使用负数，从数组尾部规定位置。</li>
<li><code>howmany</code>参数：<strong>必须，要删除的数量</strong>，如果为0，则不删除项目。</li>
<li><code>tem1,...itemX</code>参数：<strong>可选</strong>，向数组添加的新项目。</li>
</ol>
</li>
</ul>
</li>
</ul>
<hr>
</li>
<li><h2 id="字符串对象："><a href="#字符串对象：" class="headerlink" title="字符串对象："></a>字符串对象：</h2><ul>
<li><h3 id="基本包装类型："><a href="#基本包装类型：" class="headerlink" title="基本包装类型："></a>基本包装类型：</h3><ul>
<li>为了方便操作基本数据类型，<code>JavaScript</code> 还提供了三个特殊的引用类型：<code>String、Number</code>和 <code>Boolean</code>。</li>
<li><strong>基本包装类型</strong>就是把<strong>简单数据类型包装成为复杂数据类型</strong>，这样基本数据类型就有了<strong>属性和方法</strong>。</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="comment">// 下面代码有什么问题？</span></span><br><span class="line"><span class="keyword">var</span> str = <span class="string">&#x27;andy&#x27;</span>;</span><br><span class="line"><span class="built_in">console</span>.log(str.length);</span><br></pre></td></tr></table></figure>

<blockquote>
<p>按道理基本数据类型是没有属性和方法的，而对象才有属性和方法，但上面代码却可以执行，这是因为 js 会把基本数据类型包装为复杂数据类型，其执行过程如下 ：</p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="comment">// 1. 生成临时变量，把简单类型包装为复杂数据类型</span></span><br><span class="line"><span class="keyword">var</span> temp = <span class="keyword">new</span> <span class="built_in">String</span>(<span class="string">&#x27;andy&#x27;</span>);</span><br><span class="line"><span class="comment">// 2. 赋值给我们声明的字符变量</span></span><br><span class="line">str = temp;</span><br><span class="line"><span class="comment">// 3. 销毁临时变量</span></span><br><span class="line">temp = <span class="literal">null</span>;</span><br></pre></td></tr></table></figure>

<hr>
</li>
<li><h3 id="字符串的不可变"><a href="#字符串的不可变" class="headerlink" title="字符串的不可变:"></a>字符串的不可变:</h3><ul>
<li>指的是里面的<strong>值不可变</strong>，虽然看上去可以改变内容，但其实是<strong>地址变了</strong>，<strong>内存中新开辟了一个内存空间。</strong></li>
</ul>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">var</span> str = <span class="string">&#x27;abc&#x27;</span>;</span><br><span class="line">str = <span class="string">&#x27;hello&#x27;</span>;</span><br><span class="line"><span class="comment">// 当重新给 str 赋值的时候，常量&#x27;abc&#x27;不会被修改，依然在内存中</span></span><br><span class="line"><span class="comment">// 重新给字符串赋值，会重新在内存中开辟空间，这个特点就是字符串的不可变</span></span><br><span class="line"><span class="keyword">var</span> str = <span class="string">&#x27;&#x27;</span>;</span><br><span class="line"><span class="keyword">for</span> (<span class="keyword">var</span> i = <span class="number">0</span>; i &lt; <span class="number">100000</span>; i++) &#123;</span><br><span class="line">    str += i;</span><br><span class="line">&#125;</span><br><span class="line"><span class="built_in">console</span>.log(str); <span class="comment">// 这个结果需要花费大量时间来显示，因为需要不断的开辟新的空间</span></span><br></pre></td></tr></table></figure>

<ul>
<li>由于<strong>字符串的不可变</strong>，在大量拼接字符串的时候会有<strong>效率问题</strong></li>
</ul>
<hr>
</li>
<li><h3 id="根据字符返回位置"><a href="#根据字符返回位置" class="headerlink" title="根据字符返回位置:"></a>根据字符返回位置:</h3><ul>
<li>字符串所有的方法，<strong>都不会修改字符串本身(字符串是不可变的)，操作完成会返回一个新的字符串</strong>。</li>
</ul>
<table>
<thead>
<tr>
<th>方法名</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>indexOf(‘要查找的字符’，开始的位置)</td>
<td>返回指定内容在元字符串中的位置，如果找不到就返回-1，开始的位置是<code>index</code>索引号</td>
</tr>
<tr>
<td>lastIndexOf(]</td>
<td>从后往前找，只找第一个匹配的</td>
</tr>
</tbody></table>
<hr>
</li>
<li><h3 id="根据位置返回字符（重点）"><a href="#根据位置返回字符（重点）" class="headerlink" title="根据位置返回字符（重点）:"></a>根据位置返回字符（重点）:</h3><table>
<thead>
<tr>
<th align="center">方法名</th>
<th align="center">说明</th>
<th align="center">使用</th>
</tr>
</thead>
<tbody><tr>
<td align="center">charAt(index)</td>
<td align="center">返回指定位置的字符(index字符串的索引号)</td>
<td align="center">str.charAt(0)</td>
</tr>
<tr>
<td align="center">charCodeAt(index)</td>
<td align="center">获取指定位置处字符的<strong>ASCII码</strong>(index索引号)</td>
<td align="center">sur.charCodeAt(0)</td>
</tr>
<tr>
<td align="center">str[index]</td>
<td align="center">获取指定位置处字符</td>
<td align="center">HTML5，IE8+支持和charAt()等效</td>
</tr>
</tbody></table>
<h4 id="ASCII码大全"><a href="#ASCII码大全" class="headerlink" title="ASCII码大全:"></a>ASCII码大全:</h4><p><img src= "/img/loading.gif" data-lazy-src="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20200916/Nr@uM2JPif^d.png" alt="ASCII码大全"></p>
<ul>
<li>可以用<code>charCodeAt(index)</code>结合<code>ASCII</code>做些<strong>小游戏</strong>: 根据<code>ASCII</code>判断按下的那个键</li>
</ul>
<hr>
</li>
<li><h3 id="字符串操作方法（重点）"><a href="#字符串操作方法（重点）" class="headerlink" title="字符串操作方法（重点）:"></a>字符串操作方法（重点）:</h3><table>
<thead>
<tr>
<th align="center">方法名</th>
<th align="center">说明</th>
</tr>
</thead>
<tbody><tr>
<td align="center">concat(str1,str2,str3…)</td>
<td align="center">concat()方法用于连接两个或多个字符串。拼接字符串，等效于+，+更常用</td>
</tr>
<tr>
<td align="center">substr(start,length)</td>
<td align="center">从start位置开始(索引号), length 取的个数重点记住这个</td>
</tr>
<tr>
<td align="center">slice(start, end)</td>
<td align="center">从start位置开始，截取到end位置，end取不到(他们俩都是索引号)</td>
</tr>
<tr>
<td align="center">substring(start, end)</td>
<td align="center">从start位置开始，截取到end位置，end取不到基本和slice相同但是不接受负值</td>
</tr>
</tbody></table>
<hr>
</li>
<li><h3 id="replace-方法"><a href="#replace-方法" class="headerlink" title="replace()方法:"></a>replace()方法:</h3><ul>
<li><code>replace() </code>方法用于在字符串中用一些字符替换另一些字符。</li>
<li>其使用格式如下：</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line">replace(被替换的字符串， 要替换为的字符串)；</span><br></pre></td></tr></table></figure>

<hr>
</li>
<li><h3 id="split-方法"><a href="#split-方法" class="headerlink" title="split()方法:"></a>split()方法:</h3><ul>
<li><code>split()</code>方法<strong>用于切分字符串</strong>，它可以将<strong>字符串切分为数组</strong>。在切分完毕之后，返回的是一个<strong>新数组。</strong></li>
<li>例如下面代码：  </li>
</ul>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">var</span> str = <span class="string">&#x27;a,b,c,d&#x27;</span>;</span><br><span class="line"><span class="built_in">console</span>.log(str.split(<span class="string">&#x27;,&#x27;</span>));   <span class="comment">// 返回的是一个数组 [a, b, c, d]</span></span><br></pre></td></tr></table></figure>

<hr>
</li>
<li><h3 id="toUpperCase-方法"><a href="#toUpperCase-方法" class="headerlink" title="toUpperCase() 方法:"></a>toUpperCase() 方法:</h3><ul>
<li><code>toUpperCase()</code> 方法用于把<strong>字符串转换为大写</strong>。</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">var</span> oldStr = <span class="string">&#x27;fawaiKuangTU&#x27;</span></span><br><span class="line">  <span class="keyword">var</span> str = oldStr.toUpperCase()</span><br><span class="line">  <span class="built_in">console</span>.log(str);   <span class="comment">//FAWAIKUANGTU</span></span><br></pre></td></tr></table></figure>

<hr>
</li>
<li><h3 id="toLowerCase-方法"><a href="#toLowerCase-方法" class="headerlink" title="toLowerCase()方法"></a>toLowerCase()方法</h3><ul>
<li>转换小写 方法同上</li>
</ul>
</li>
</ul>
</li>
</ul>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="mailto:undefined">六根清静</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://liugenqingjing2.coding.me/2020/09/14/JavaScript%E7%9F%A5%E8%AF%86%E7%82%B9%E6%80%BB%E7%BB%93-%E5%85%AB-JavaScript-%E5%86%85%E7%BD%AE%E5%AF%B9%E8%B1%A1/">https://liugenqingjing2.coding.me/2020/09/14/JavaScript知识点总结-八-JavaScript-内置对象/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://liugenqingjing2.coding.me" target="_blank">小何blog (记录美好)</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/%E7%B3%BB%E5%88%97%F0%9F%8F%AC/">系列🏬</a><a class="post-meta__tags" href="/tags/JavaScript/">JavaScript</a><a class="post-meta__tags" href="/tags/ECMAScript/">ECMAScript</a></div><div class="post_share"><div class="social-share" data-image="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20200914/it!NQ33FHCp7.jpg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/social-share.js/dist/css/share.min.css"><script src="https://cdn.jsdelivr.net/npm/social-share.js/dist/js/social-share.min.js" defer></script></div></div><div class="post-reward"><div class="reward-button"><i class="fas fa-qrcode"></i> 打赏<div class="reward-main"><ul class="reward-all"><li class="reward-item"><a href="http://qew58kkb2.hn-bkt.clouddn.com/wechat%20%20%281%29.png" target="_blank"><img class="post-qr-code-img" data-lazy-src="http://qew58kkb2.hn-bkt.clouddn.com/wechat%20%20%281%29.png" alt="微信"/></a><div class="post-qr-code-desc">微信</div></li></ul></div></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/2020/09/16/%E5%80%92%E8%AE%A1%E6%97%B6%E5%8A%A8%E7%94%BB/"><img class="prev-cover" data-lazy-src="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20200916/lHVXVfm!v!kJ.jpg" onerror="onerror=null;src='/img/404.jpg'"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">倒计时动画</div></div></a></div><div class="next-post pull-right"><a href="/2020/09/13/JavaScript%E7%9F%A5%E8%AF%86%E7%82%B9%E6%80%BB%E7%BB%93-%E4%B8%83-JavaScript%E9%A2%84%E8%A7%A3%E6%9E%90%E5%92%8C%E5%AF%B9%E8%B1%A1/"><img class="next-cover" data-lazy-src="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20200913/WKp@vPE1Cm1Z.jpg" onerror="onerror=null;src='/img/404.jpg'"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">JavaScript知识点总结(七.JavaScript预解析和对象)</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span> 相关推荐</span></div><div class="relatedPosts-list"><div><a href="/2020/09/13/JavaScript知识点总结-七-JavaScript预解析和对象/" title="JavaScript知识点总结(七.JavaScript预解析和对象)"><img class="cover" data-lazy-src="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20200913/WKp@vPE1Cm1Z.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-09-13</div><div class="title">JavaScript知识点总结(七.JavaScript预解析和对象)</div></div></a></div><div><a href="/2020/09/09/JavaScript知识点总结-五-ECMAScript之数组/" title="JavaScript知识点总结(五.ECMAScript之数组)"><img class="cover" data-lazy-src="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/文章bg/v2-fb37f4ec3f0e1eff232ec6e3b225f86a_r.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-09-09</div><div class="title">JavaScript知识点总结(五.ECMAScript之数组)</div></div></a></div><div><a href="/2020/09/10/JavaScript知识点总结-六-ECMAScrip之函数和作用域/" title="JavaScript知识点总结(六.ECMAScrip之函数和作用域)"><img class="cover" data-lazy-src="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/文章bg/v2-311744a9352d16d336652eb4577fa237_r.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-09-10</div><div class="title">JavaScript知识点总结(六.ECMAScrip之函数和作用域)</div></div></a></div><div><a href="/2020/09/08/JavaScript知识点总结-四-ECMAScript之运算符和流程控制分支结构/" title="JavaScript知识点总结(四.ECMAScript之运算符和流程控制分支结构)"><img class="cover" data-lazy-src="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/文章bg/v2-62a1837d21c646084077622c3d2115b0_r.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-09-08</div><div class="title">JavaScript知识点总结(四.ECMAScript之运算符和流程控制分支结构)</div></div></a></div><div><a href="/2020/09/06/JavaScript知识点总结-三-ECMAScript之变量和数据类型/" title="JavaScript知识点总结(三.ECMAScript之变量和数据类型)"><img class="cover" data-lazy-src="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/文章bg/v2-a049026224c43dcadeabad571c8d0d27_r.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-09-06</div><div class="title">JavaScript知识点总结(三.ECMAScript之变量和数据类型)</div></div></a></div><div><a href="/2020/09/17/JavaScript知识点总结-九-JavaScript的Web-APIs简介/" title="JavaScript知识点总结(九.JavaScript的Web APIs简介)"><img class="cover" data-lazy-src="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20200917/7cKUzRmy@FxZ.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-09-17</div><div class="title">JavaScript知识点总结(九.JavaScript的Web APIs简介)</div></div></a></div></div></div><hr/><div id="post-comment"><div class="comment-head"><div class="comment-headline"><i class="fas fa-comments fa-fw"></i><span> 评论</span></div></div><div class="comment-wrap"><div><div class="vcomment" id="vcomment"></div></div></div></div></div><div class="aside_content" id="aside_content"><div class="card-widget card-info"><div class="card-content"><div class="card-info-avatar is-center"><img class="avatar-img" data-lazy-src="http://01.027cgb.com/632500/1576904533264.jpg" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/><div class="author-info__name">六根清静</div><div class="author-info__description">记录美好，记录生活，记录学习</div></div><div class="card-info-data"><div class="card-info-data-item is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">138</div></a></div><div class="card-info-data-item is-center"><a href="/tags/"><div class="headline">标签</div><div class="length-num">63</div></a></div><div class="card-info-data-item is-center"><a href="/categories/"><div class="headline">分类</div><div class="length-num">8</div></a></div></div><a class="button--animated" id="card-info-btn" target="_blank" rel="noopener" href="https://gitee.com/he_chaoming/dashboard/projects?scope=public&amp;&amp;sort="><i class="fab fa-gofore"></i><span>My Gitee</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://github.com/he1213114428" target="_blank" title="Github"><i class="fab fa-github"></i></a><a class="social-icon" href="mailto:484695754@qq.com" target="_blank" title="Email"><i class="fas fa-envelope"></i></a><a class="social-icon" href="tencent://message/?uin=484695754" target="_blank" title="QQ"><i class="fab fa-qq"></i></a></div></div></div><div class="card-widget card-recent-post"><div id="gamenews"><div class="card-content"><div class="item-headline"><i class="fas fa-cube"></i><span>ROLL资讯</span><i class="fas fa-retweet" @click="changetype(current)" style="float:right;margin-top:8px"></i></div><div class="newsbar"><span v-for="(type, index) in listtype" v-on:click="addClass(index)" v-bind:class="{ listtypeon:index==current}">{{type}}</span></div><div class="aside-list"><div class="aside-list-item" v-for="(news,index) in newsvue"><a class="thumbnail" href="javascript:void(0)" @click="getnewsdata(index)" :title="news.title"><img class="loaded" onerror="this.onerror=null;this.src='/img/404.jpg'" data-ll-status="loaded" :src="news.imgList[0]"/></a><div class="content"><a class="title" href="javascript:void(0)" @click="getnewsdata(index)" :title="news.title">{{news.title}}</a><time>{{news.postTime}}</time></div></div></div></div><div id="newsmodal"><button class="modalclose" @click="hidemodle()">关闭</button><h2>{{newpostvue.title}} </h2><h4>{{newpostvue.ptime}} &nbsp;&nbsp; {{newpostvue.source}}</h4><div v-html="newpostvue.content"></div></div></div></div><div class="card-widget card-shuo"><div class="card-content" style="height:auto;min-height:280px;"><div class="item-headline"><i class="fas fa-comments"></i><span>&#x8BF4;&#x8BF4</span><a id="shuovisualchange" style="cursor:pointer;float:right" onclick="shuovisualchange()">编辑</a></div><div id="artitalk_main" style="width:100%;height:100%;padding:10px"></div></div></div><div class="sticky_layout"></div><div class="card-widget card-history"><div class="card-content"><div class="item-headline"><i class="fas fa-paw fa-spin"></i><span>那年今日</span></div><div id="history-news" style="height: 100px;overflow: hidden;"><div id="history-card"></div></div></div></div><div class="card-widget card-announcement"><div class="card-content"><div class="item-headline"><i class="fas fa-bullhorn card-announcement-animation"></i><span>公告</span></div><div class="announcement_content">大学生一枚，软件工程，想做全栈攻城狮，哈哈，有兴趣可以加 QQ:484695754 (也可以点上面的logo)，一起交流学习</div></div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="card-content"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#JavaScript-%E5%86%85%E7%BD%AE%E5%AF%B9%E8%B1%A1%EF%BC%9A"><span class="toc-number">1.</span> <span class="toc-text">JavaScript 内置对象：</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%86%85%E7%BD%AE%E5%AF%B9%E8%B1%A1%EF%BC%9A"><span class="toc-number">1.1.</span> <span class="toc-text">内置对象：</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Math-%E5%AF%B9%E8%B1%A1"><span class="toc-number">1.2.</span> <span class="toc-text">Math 对象:</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#Math-%E6%A6%82%E8%BF%B0"><span class="toc-number">1.2.1.</span> <span class="toc-text">Math 概述:</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%B8%B8%E7%94%A8%E7%9A%84%E5%A6%82%E4%B8%8B"><span class="toc-number">1.2.1.1.</span> <span class="toc-text">常用的如下:</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E9%9A%8F%E6%9C%BA%E6%95%B0%E6%96%B9%E6%B3%95-random-%EF%BC%9A"><span class="toc-number">1.2.2.</span> <span class="toc-text">随机数方法 random()：</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%97%A5%E6%9C%9F%E5%AF%B9%E8%B1%A1"><span class="toc-number">1.3.</span> <span class="toc-text">日期对象:</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#Date-%E6%A6%82%E8%BF%B0"><span class="toc-number">1.3.1.</span> <span class="toc-text">Date 概述:</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Date-%E6%96%B9%E6%B3%95%E7%9A%84%E4%BD%BF%E7%94%A8"><span class="toc-number">1.3.2.</span> <span class="toc-text">Date()方法的使用:</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%95%88%E6%9E%9C"><span class="toc-number">1.3.2.1.</span> <span class="toc-text">效果:</span></a></li></ol></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link"><span class="toc-number">1.4.</span> <span class="toc-text"></span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%97%A5%E6%9C%9F%E6%A0%BC%E5%BC%8F%E5%8C%96%EF%BC%9A"><span class="toc-number">1.4.1.</span> <span class="toc-text">日期格式化：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%A1%88%E4%BE%8B"><span class="toc-number">1.4.2.</span> <span class="toc-text">案例:</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%95%88%E6%9E%9C-1"><span class="toc-number">1.4.2.1.</span> <span class="toc-text">效果:</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%95%88%E6%9E%9C-2"><span class="toc-number">1.4.2.2.</span> <span class="toc-text">效果:</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%8E%B7%E5%8F%96%E6%97%A5%E6%9C%9F%E7%9A%84%E6%80%BB%E7%9A%84%E6%AF%AB%E7%A7%92%E5%BD%A2%E5%BC%8F-%E6%97%B6%E9%97%B4%E6%88%B3-%EF%BC%9A"><span class="toc-number">1.4.3.</span> <span class="toc-text">获取日期的总的毫秒形式(时间戳)：</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%95%88%E6%9E%9C-3"><span class="toc-number">1.4.3.1.</span> <span class="toc-text">效果:</span></a></li></ol></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%95%B0%E7%BB%84%E5%AF%B9%E8%B1%A1%EF%BC%9A"><span class="toc-number">1.5.</span> <span class="toc-text">数组对象：</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%95%B0%E7%BB%84%E5%AF%B9%E8%B1%A1%E7%9A%84%E5%88%9B%E5%BB%BA%EF%BC%9A"><span class="toc-number">1.5.1.</span> <span class="toc-text">数组对象的创建：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%A3%80%E6%B5%8B%E6%98%AF%E5%90%A6%E4%B8%BA%E6%95%B0%E7%BB%84"><span class="toc-number">1.5.2.</span> <span class="toc-text">检测是否为数组:</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%B7%BB%E5%8A%A0%E5%88%A0%E9%99%A4%E6%95%B0%E7%BB%84%E5%85%83%E7%B4%A0%E7%9A%84%E6%96%B9%E6%B3%95"><span class="toc-number">1.5.3.</span> <span class="toc-text">添加删除数组元素的方法:</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%95%B0%E7%BB%84%E6%8E%92%E5%BA%8F%EF%BC%9A"><span class="toc-number">1.5.4.</span> <span class="toc-text">数组排序：</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%B3%A8"><span class="toc-number">1.5.4.1.</span> <span class="toc-text">注:</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#sort-%E7%BC%BA%E9%99%B7-js%E6%95%B0%E7%BB%84%E7%9A%84sort%E6%96%B9%E6%B3%95%E6%80%BB%E4%BC%9A%E4%BB%A5%E7%AC%AC%E4%B8%80%E4%B8%AA%E5%AD%97%E7%AC%A6%E7%9A%84ASCII%E5%80%BC%E6%9D%A5%E8%BF%9B%E8%A1%8C%E6%AF%94%E8%BE%83%E6%8E%92%E5%BA%8F"><span class="toc-number">1.5.4.2.</span> <span class="toc-text">sort()缺陷:  js数组的sort方法总会以第一个字符的ASCII值来进行比较排序</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%95%B0%E7%BB%84%E7%B4%A2%E5%BC%95%E6%96%B9%E6%B3%95"><span class="toc-number">1.5.5.</span> <span class="toc-text">数组索引方法:</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%A1%88%E4%BE%8B%E6%95%B0%E7%BB%84%E5%8E%BB%E9%87%8D"><span class="toc-number">1.5.5.1.</span> <span class="toc-text">案例数组去重:</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%95%88%E6%9E%9C-4"><span class="toc-number">1.5.5.2.</span> <span class="toc-text">效果:</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%95%B0%E7%BB%84%E8%BD%AC%E6%8D%A2%E4%B8%BA%E5%AD%97%E7%AC%A6%E4%B8%B2"><span class="toc-number">1.5.6.</span> <span class="toc-text">数组转换为字符串:</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%85%B6%E4%BB%96%E6%96%B9%E6%B3%95"><span class="toc-number">1.5.7.</span> <span class="toc-text">其他方法:</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E8%A7%A3%E9%87%8A"><span class="toc-number">1.5.7.1.</span> <span class="toc-text">解释:</span></a></li></ol></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%AD%97%E7%AC%A6%E4%B8%B2%E5%AF%B9%E8%B1%A1%EF%BC%9A"><span class="toc-number">1.6.</span> <span class="toc-text">字符串对象：</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%9F%BA%E6%9C%AC%E5%8C%85%E8%A3%85%E7%B1%BB%E5%9E%8B%EF%BC%9A"><span class="toc-number">1.6.1.</span> <span class="toc-text">基本包装类型：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%AD%97%E7%AC%A6%E4%B8%B2%E7%9A%84%E4%B8%8D%E5%8F%AF%E5%8F%98"><span class="toc-number">1.6.2.</span> <span class="toc-text">字符串的不可变:</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%A0%B9%E6%8D%AE%E5%AD%97%E7%AC%A6%E8%BF%94%E5%9B%9E%E4%BD%8D%E7%BD%AE"><span class="toc-number">1.6.3.</span> <span class="toc-text">根据字符返回位置:</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%A0%B9%E6%8D%AE%E4%BD%8D%E7%BD%AE%E8%BF%94%E5%9B%9E%E5%AD%97%E7%AC%A6%EF%BC%88%E9%87%8D%E7%82%B9%EF%BC%89"><span class="toc-number">1.6.4.</span> <span class="toc-text">根据位置返回字符（重点）:</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#ASCII%E7%A0%81%E5%A4%A7%E5%85%A8"><span class="toc-number">1.6.4.1.</span> <span class="toc-text">ASCII码大全:</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%AD%97%E7%AC%A6%E4%B8%B2%E6%93%8D%E4%BD%9C%E6%96%B9%E6%B3%95%EF%BC%88%E9%87%8D%E7%82%B9%EF%BC%89"><span class="toc-number">1.6.5.</span> <span class="toc-text">字符串操作方法（重点）:</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#replace-%E6%96%B9%E6%B3%95"><span class="toc-number">1.6.6.</span> <span class="toc-text">replace()方法:</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#split-%E6%96%B9%E6%B3%95"><span class="toc-number">1.6.7.</span> <span class="toc-text">split()方法:</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#toUpperCase-%E6%96%B9%E6%B3%95"><span class="toc-number">1.6.8.</span> <span class="toc-text">toUpperCase() 方法:</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#toLowerCase-%E6%96%B9%E6%B3%95"><span class="toc-number">1.6.9.</span> <span class="toc-text">toLowerCase()方法</span></a></li></ol></li></ol></li></ol></div></div></div><div class="card-widget card-recent-post"><div class="card-content"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/2021/03/21/Node-js%E5%AD%A6%E4%B9%A0-%E4%BA%8C%E5%8D%81%E4%B8%89-%E8%B7%A8%E5%9F%9F%E4%BB%8B%E7%BB%8D%E5%92%8CJSONP%E4%BB%8B%E7%BB%8D/" title="Node.js学习(二十三.跨域介绍和JSONP介绍)"><img data-lazy-src="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20210321/qWPEashJOuNK.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Node.js学习(二十三.跨域介绍和JSONP介绍)"/></a><div class="content"><a class="title" href="/2021/03/21/Node-js%E5%AD%A6%E4%B9%A0-%E4%BA%8C%E5%8D%81%E4%B8%89-%E8%B7%A8%E5%9F%9F%E4%BB%8B%E7%BB%8D%E5%92%8CJSONP%E4%BB%8B%E7%BB%8D/" title="Node.js学习(二十三.跨域介绍和JSONP介绍)">Node.js学习(二十三.跨域介绍和JSONP介绍)</a><time datetime="2021-03-21T13:40:58.000Z" title="发表于 2021-03-21 21:40:58">2021-03-21</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2021/03/20/Node-js%E5%AD%A6%E4%B9%A0-%E4%BA%8C%E5%8D%81%E4%BA%8C-Node-js%E9%A1%B9%E7%9B%AE%E6%B5%81%E7%A8%8B-%E4%B8%8B/" title="Node.js学习(二十二.Node.js项目流程(下))"><img data-lazy-src="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20210320/CvAoe6kC5*f2.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Node.js学习(二十二.Node.js项目流程(下))"/></a><div class="content"><a class="title" href="/2021/03/20/Node-js%E5%AD%A6%E4%B9%A0-%E4%BA%8C%E5%8D%81%E4%BA%8C-Node-js%E9%A1%B9%E7%9B%AE%E6%B5%81%E7%A8%8B-%E4%B8%8B/" title="Node.js学习(二十二.Node.js项目流程(下))">Node.js学习(二十二.Node.js项目流程(下))</a><time datetime="2021-03-20T14:33:29.000Z" title="发表于 2021-03-20 22:33:29">2021-03-20</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2021/03/15/Node-js%E5%AD%A6%E4%B9%A0-%E4%BA%8C%E5%8D%81%E4%B8%80-Node-js%E9%A1%B9%E7%9B%AE%E6%B5%81%E7%A8%8B-%E4%B8%AD/" title="Node.js学习(二十一.Node.js项目流程(中))"><img data-lazy-src="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20210320/gSrAfCznw@^F.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Node.js学习(二十一.Node.js项目流程(中))"/></a><div class="content"><a class="title" href="/2021/03/15/Node-js%E5%AD%A6%E4%B9%A0-%E4%BA%8C%E5%8D%81%E4%B8%80-Node-js%E9%A1%B9%E7%9B%AE%E6%B5%81%E7%A8%8B-%E4%B8%AD/" title="Node.js学习(二十一.Node.js项目流程(中))">Node.js学习(二十一.Node.js项目流程(中))</a><time datetime="2021-03-15T04:35:12.000Z" title="发表于 2021-03-15 12:35:12">2021-03-15</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2021/03/14/Node-js%E5%AD%A6%E4%B9%A0-%E4%BA%8C%E5%8D%81-Node-js%E9%A1%B9%E7%9B%AE%E6%B5%81%E7%A8%8B(%E4%B8%8A)/" title="Node.js学习(二十.Node.js项目流程(上))"><img data-lazy-src="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20210320/UMp@B^akHmf8.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Node.js学习(二十.Node.js项目流程(上))"/></a><div class="content"><a class="title" href="/2021/03/14/Node-js%E5%AD%A6%E4%B9%A0-%E4%BA%8C%E5%8D%81-Node-js%E9%A1%B9%E7%9B%AE%E6%B5%81%E7%A8%8B(%E4%B8%8A)/" title="Node.js学习(二十.Node.js项目流程(上))">Node.js学习(二十.Node.js项目流程(上))</a><time datetime="2021-03-14T14:36:58.000Z" title="发表于 2021-03-14 22:36:58">2021-03-14</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2021/02/27/Node-js%E5%AD%A6%E4%B9%A0-%E5%8D%81%E4%B9%9D-%E5%B0%81%E8%A3%85%E6%93%8D%E4%BD%9C%E6%95%B0%E6%8D%AE%E5%BA%93%E5%92%8CCSRF/" title="Node.js学习(十九.封装操作数据库和CSRF)"><img data-lazy-src="https://gitee.com/he_chaoming/blog_tuchuang/raw/master/20210227/EcgLTE4WPOp^.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Node.js学习(十九.封装操作数据库和CSRF)"/></a><div class="content"><a class="title" href="/2021/02/27/Node-js%E5%AD%A6%E4%B9%A0-%E5%8D%81%E4%B9%9D-%E5%B0%81%E8%A3%85%E6%93%8D%E4%BD%9C%E6%95%B0%E6%8D%AE%E5%BA%93%E5%92%8CCSRF/" title="Node.js学习(十九.封装操作数据库和CSRF)">Node.js学习(十九.封装操作数据库和CSRF)</a><time datetime="2021-02-27T13:20:18.000Z" title="发表于 2021-02-27 21:20:18">2021-02-27</time></div></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2021 By 六根清静</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div><div class="footer_custom_text">Hi,  welcome  to  my  <a  href="">blog</a>!</div><div class="icp"><a><img class="icp-icon" src="/img/icp.png" alt="ICP"/><span>豫ICP备2020025430号</span></a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="translateLink" type="button" title="简繁转换">简</button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="chat_btn" type="button" title="rightside.chat_btn"><i class="fas fa-sms"></i></button><a id="to_comment" href="#post-comment" title="直达评论"><i class="fas fa-comments"></i></a><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div id="local-search"><div class="search-dialog"><div class="search-dialog__title" id="local-search-title">本地搜索</div><div id="local-input-panel"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div></div><hr/><div id="local-search-results"><div id="local-hits"></div><div id="local-stats"><div class="local-search-stats__hr" id="hr"><span>由</span> <a target="_blank" rel="noopener" href="https://github.com/wzpan/hexo-generator-search" style="color:#49B1F5;">hexo-generator-search</a>
 <span>提供支持</span></div></div></div><span class="search-close-button"><i class="fas fa-times"></i></span></div><div id="search-mask"></div></div><div><script src="https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js"></script><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="/js/tw_cn.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.js"></script><script src="https://cdn.jsdelivr.net/npm/instant.page/instantpage.min.js" type="module" defer></script><script src="https://cdn.jsdelivr.net/npm/vanilla-lazyload/dist/lazyload.iife.min.js"></script><script src="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.js"></script><script src="/js/search/local-search.js"></script><script async="async">var preloader = {
  endLoading: () => {
    document.body.style.overflow = 'auto';
    document.getElementById('loading-box').classList.add("loaded")
  },
  initLoading: () => {
    document.body.style.overflow = '';
    document.getElementById('loading-box').classList.remove("loaded")

  }
}
window.addEventListener('load',()=> {preloader.endLoading()})
setTimeout(function(){preloader.endLoading();}, 50000);</script><div class="js-pjax"><script>function loadValine () {
  function initValine () {
    let initData = {
      el: '#vcomment',
      appId: 'kW2ft895T235y7DxmyJmXX5X-MdYXbMMI',
      appKey: 'v0zBPCAdwiJ0xg4s4eSfusLD',
      placeholder: '建议使用QQ邮箱，评论头像采用QQ头像',
      avatar: 'monsterid',
      meta: 'nick,mail,link'.split(','),
      pageSize: '10',
      lang: 'zh-CN',
      recordIP: false,
      serverURLs: 'https://???????.api.lncldglobal.com',
      emojiCDN: '',
      emojiMaps: "",
      enableQQ: true,
      path: window.location.pathname,
      master: '1f76478c4ec918ffc6d50de6b68db531'.split(','),
      friends: '5c?????bfe6rfc72a????e268ad3819c,7c?????bfe65fc02a????e2????3919c'.split(','),
      tagMeta: '博主,小伙伴,访客'.split(',')
    }

    if (true) { 
      initData.requiredFields= ('nick,mail'.split(','))
    }
    
    if (false) {
      const otherData = false
      initData = Object.assign({}, initData, otherData)
    }
    
    const valine = new Valine(initData)
  }

  if (typeof Valine === 'function') initValine() 
  else $.getScript('https://cdn.jsdelivr.net/gh/HCLonely/Valine@latest/dist/Valine.min.js', initValine)
}

if ('Valine' === 'Valine' || !true) {
  if (true) btf.loadComment(document.querySelector('#vcomment'),loadValine)
  else setTimeout(() => loadValine(), 0)
} else {
  function loadOtherComment () {
    loadValine()
  }
}</script><script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div><script src='https://cdn.jsdelivr.net/npm/artitalk'></script><script> $(".category-list-count").prepend("<i class=\"fas fa-book\"></i>");</script><script src="/js/list.js"></script><script src="/js/gitcalendar.js"></script><script src="/js/calendar.js"></script><script src="/js/xkTool.js"></script><script src="/js/pjax.js"></script><script src="/magnet/js/vue.min.js"></script><script src="/magnet/js/catalogMagnet.js"></script><script src="/js/airvisualapi.js"></script><script src="/js/history.js"></script><script src="/js/historyroll.js"></script><script src="/js/change.js"></script><script type="text/javascript" src="https://www.airvisual.com/scripts/widget_v2.0.js"></script><script> setTimeout(function(){$('.monoline').eq(0).html($(".monoline strong").eq(0).text().replace('°','℃'));},5000);</script><script src="https://cdn.jsdelivr.net/gh/sviptzk/HexoStaticFile@latest/Hexo/js/mouse_snow.min.js"></script><script src="/js/myBg.js"></script><script src="/js/shuo.js"></script><script src="/js/artitalkkey.js"></script><script src="/news/js/keys.js"></script><script src="/news/js/news.js"></script><script src="https://cdn.jsdelivr.net/gh/sviptzk/StaticFile_HEXO@latest/butterfly/js/pool.min.js"><script src="https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js"></script><script src="/stars/stars.js"></script><script src="https://cdn1.lncld.net/static/js/3.5.0/av-min.js"></script><script src="/zan/zan.js"></script><div class="aplayer no-destroy" data-id="2916766519" data-server="netease" data-type="playlist" data-fixed="true" data-mini="true" data-listFolded="false" data-order="random" data-preload="none" data-autoplay="false" muted></div><script src="/swiper/swiper.min.js"></script><script src="/swiper/swiperindex.js"></script><script async src="//at.alicdn.com/t/font_2264842_3izu8i5eoc2.js"></script><canvas class="fireworks" mobile="false"></canvas><script src="/js/third-party/fireworks.js"></script><script src="/js/third-party/activate-power-mode.js"></script><script>POWERMODE.colorful = true;
POWERMODE.shake = true;
POWERMODE.mobile = false;
document.body.addEventListener('input', POWERMODE);
</script><script>(function(i,s,o,g,r,a,m){i["DaoVoiceObject"]=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;a.charset="utf-8";m.parentNode.insertBefore(a,m)})(window,document,"script",('https:' == document.location.protocol ? 'https:' : 'http:') + "//widget.daovoice.io/widget/6fdec148.js","daovoice")
</script><script>var isChatBtn = true
daovoice('init', {
  app_id: '6fdec148',},{
  launcher: { 
     disableLauncherIcon: isChatBtn // 悬浮 ICON 是否显示
  },
});
daovoice('update');

if (isChatBtn) {
  var chatBtnFn = () => {
    var chatBtn = document.getElementById("chat_btn")
    chatBtn.addEventListener("click", function(){
      daovoice('show')
    });
  }
  chatBtnFn()
} else {
  if (true) {
    function chatBtnHide () {
      daovoice('update', {},{
        launcher: { 
        disableLauncherIcon: true // 悬浮 ICON 是否显示
        },
      });
    }
    function chatBtnShow () {
      daovoice('update', {},{
        launcher: { 
        disableLauncherIcon: false // 悬浮 ICON 是否显示
        },
      });
    }
  }
}</script><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.css"><script src="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.js"></script><script src="https://cdn.jsdelivr.net/gh/metowolf/MetingJS@1.2/dist/Meting.min.js"></script></div><script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"debug":false,"model":{"scale":1,"hHeadPos":0.5,"vHeadPos":0.618,"jsonPath":"/live2dw/assets/unitychan.model.json"},"display":{"superSample":2,"width":150,"height":300,"position":"right","hOffset":0,"vOffset":-20},"mobile":{"show":true,"scale":0.6},"react":{"opacityDefault":0.7,"opacityOnHover":0.8},"log":false});</script></body></html>